package com.jh.user.business.impl;

import java.util.Date;

import javax.persistence.EntityManager;
import org.springframework.transaction.annotation.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.jh.user.business.UserRelationBusiness;
import com.jh.user.pojo.UserAgentChange;
import com.jh.user.repository.UserAgentChangeRepository;

@Service
public class UserRelationBusinessImpl implements UserRelationBusiness{

	@Autowired
	private UserAgentChangeRepository userAgentChangeRepository;


	@Autowired
	private EntityManager em;


	@Override
	public Page<UserAgentChange> findUserAgentChangeByUserid(long userid, Pageable pageAble) {
		return userAgentChangeRepository.findUserAgentChangeByUserid(userid, pageAble);
	}

	@Override
	public Page<UserAgentChange> findUserAgentChange(Pageable pageAble) {
		return userAgentChangeRepository.findAll(pageAble);
	}

	@Transactional
	@Override
	public UserAgentChange saveUserAgentChange(UserAgentChange userAgentChange) {

		UserAgentChange result = userAgentChangeRepository.save(userAgentChange);
		em.flush();
		return result;
	}



	@Override
	public Page<UserAgentChange> findUserAgentChange(Date startTime,
													 Pageable pageAble) {
		// TODO Auto-generated method stub
		return userAgentChangeRepository.findUserAgentChangeByStartTime(startTime, pageAble);
	}

	@Override
	public Page<UserAgentChange> findUserAgentChange(Date startTime,
													 Date endTime, Pageable pageAble) {

		return userAgentChangeRepository.findUserAgentChangeByStartEndTime(startTime, endTime, pageAble);
	}




}
